package com.housekeeping.housekeeping.adManager.utils;

import java.io.Serializable;

/**
 * @author hua
 * @version JDK1.8
 * @date 2021/1/15 17:49
 *  实现序列化接口
 *  将数据转化为json格式
 */
public class ResponseEntity<T> implements Serializable {
    //状态码
    private int status;
    //回调信息
    private String msg;
    //数据 暂时不知道是什么格式
    private T data;

    public static<T> ResponseEntity<T> success(T data){
        ResponseEntity<T> entity = new ResponseEntity<>();
        entity.setData(data);
        entity.setStatus(200);
        entity.setMsg("success");
        return entity;
    }

    public static <T> ResponseEntity<T> error(){
        return error(404,"error");
    }

    public static <T> ResponseEntity<T> error(int status, String msg) {
        ResponseEntity<T> entity = new ResponseEntity<>();
        entity.setStatus(status);
        entity.setMsg(msg);
        return entity;
    }

    public static <T> ResponseEntity<T> error(ResponseCode responseCode) {
        ResponseEntity<T> entity = new ResponseEntity<>();
        entity.setStatus(responseCode.getStatus());
        entity.setMsg(responseCode.getMsg());
        return entity;
    }

    public ResponseEntity() {
    }

    public ResponseEntity(int status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResponseEntity{" +
                "status=" + status +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
